//: C10:Statfun.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Static vars inside functions
#include "../require.h"
#include <iostream>
using namespace std;

char onechar(const char* string = 0)
{
    static const char* s;
    if (string) {
        s = string;
        return *s;
    } else
        require(s, "un-initialized s");
    if (*s == '\0')
        return 0;
    return *s++;
}

char* a = "abcdefghijklmnopqrstuvwxyz";

int main()
{
    // Onechar(); // require() fails
    onechar(a); // Initializes s to a
    char c;
    while ((c = onechar()) != 0)
        cout << c << endl;
} ///:~
